package book.nettyinaction.ch05;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.CompositeByteBuf;
import io.netty.buffer.Unpooled;

/**
 *
 * 代码清单 5-4 使用 CompositeByteBuf 的复合缓冲区模式
 */
public class Demo004CopositeByteBuf {

    public static void main(String[] args) {
        CompositeByteBuf messageBuf = Unpooled.compositeBuffer();
        ByteBuf headerBuf = null; // can be backing or direct
        ByteBuf bodyBuf   = null; // can be backing or direct
        messageBuf.addComponents( headerBuf, bodyBuf ); // 将 ByteBuf 实例追加到 CompositeByteBuf

        messageBuf.removeComponent( 0 );  // remove the header
        for ( ByteBuf buf : messageBuf ) { // 循环遍历所有的 ByteBuf 实例
            System.out.println(buf.toString());
        }
    }
}
